﻿using System;
using System.Collections.Generic;
using System.Linq;
using System.Web;
using System.Web.UI;
using System.Web.UI.WebControls;

using System.Data.Linq;
using System.Data;
using System.Data.SqlClient;
using DAL;

public partial class ShowDetails : System.Web.UI.Page
{
    protected void Page_Load(object sender, EventArgs e)
    {
        if (!IsPostBack)
        {
            
            Frame.Global.GlobalFunctions.SetGridView(ShowDetails_ASPxGridView_ShowInfos, true);
            Frame.Global.GlobalFunctions.InitComboBoxColumn(ShowDetails_ASPxGridView_ShowInfos.Columns["t_Type_ID"], "TypeInfo", "Type_Name", "Type_ID");
            Frame.Global.GlobalFunctions.InitComboBoxColumn(ShowDetails_ASPxGridView_ShowInfos.Columns["t_Community_ID"], "Community", "Community_Name", "Community_ID");
            ShowDetails_ASPxGridView_ShowInfos.SettingsText.PopupEditFormCaption = "编辑";

            //判断用户是否已经登录
            try
            {
                if (!CMSUser.Current.IsLogin)
                {
                    Response.Redirect("~/Login.aspx");
                }
            }
            catch (Exception)
            {
                Response.Redirect("~/Login.aspx");
            }
            string name = CMSUser.Current.Name;
            if (!name.Equals("Administrator"))
            {
                // this.ShowDetails_ASPxGridView_ShowInfos.SettingsText.CommandEdit = "";
                this.ShowDetails_ASPxGridView_ShowInfos.SettingsText.CommandDelete = "";
            }
            //string username = CMSUser.Current.Name;
            //string[] Communities;
            //string CommunityName = Frame.Global.GlobalSqlHelper.ExcuteSQLScalar("select Communities from Users where UserName='" + username + "'").ToString();
            //Communities = CommunityName.Split('|');
         
            //for (int i = 0; i < Communities.Length; i++)
            //{
            //    string strSql = "select * from ProjectDetails where Community_ID='" + Communities[i] + "'";
            //    int count=Convert.ToInt32(Frame.Global.GlobalSqlHelper.ExcuteSQLScalar(strSql));
            //    if (count > 0)
            //    {
            //        DataTable dt = Frame.Global.GlobalSqlHelper.ExecuteSQLToDataTable(strSql);
            //        this.ShowDetails_ASPxGridView_ShowInfos.DataSource = dt;
            //        this.ShowDetails_ASPxGridView_ShowInfos.DataBind();
            //    }
            //}
          
        }
       
    }

    //为gridview绑定数据
    private void databind()
    {
        string username = CMSUser.Current.Name;
        int count = 0;
        string strSql = "SELECT * FROM Community INNER JOIN ProjectDetails ON Community.Community_ID = ProjectDetails.Community_ID INNER JOIN TypeInfo ON ProjectDetails.Type_ID = TypeInfo.Type_ID INNER JOIN Users ON Community.Community_ID = Users.Community_ID and Users.UserName='" + username + "'";
      //  string strSql = "SELECT * FROM Community INNER JOIN ProjectDetailsON Community.Community_ID = ProjectDetails.Community_ID INNER JOIN TypeInfo ON ProjectDetails.Type_ID = TypeInfo.Type_ID INNER JOIN Users ON Community.Community_ID = Users.Community_IDand Users.LoginName=ASD";
        count = Convert.ToInt32(Frame.Global.GlobalSqlHelper.ExcuteSQLScalar(strSql));
        if (count > 0)
        {
            DataTable dt = Frame.Global.GlobalSqlHelper.ExecuteSQLToDataTable(strSql);
            this.ShowDetails_ASPxGridView_ShowInfos.DataSource = dt;
            this.ShowDetails_ASPxGridView_ShowInfos.DataBind();
        }

    }
}